using UnityEngine;
using UnityEngine.EventSystems;

namespace Gj
{
    public class ModelHandleHelper : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
    {
        public GameObject obj;
        private Vector2 deltaPos = Vector2.zero;
        private Vector2 oldPosition = Vector2.zero;

        public void OnDrag(PointerEventData eventData)
        {
            var newPosition = eventData.position;
            if (oldPosition != Vector2.zero)
            {
                deltaPos = newPosition - oldPosition;
                obj.transform.Rotate(0, deltaPos.x * -1, 0, Space.World);
            }

            oldPosition = newPosition;
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            oldPosition = Vector2.zero;
        }

        public void OnPointerUp(PointerEventData eventData)
        {
        }
    }
}